package com.lsfb.signln.My.Feedback;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.lsfb.signln.Login.LoginActivity;
import com.lsfb.signln.R;
import com.lsfb.signln.Utils.LittleUtils;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.DensityUtils;
import com.zgscwjm.lsfbbasetemplate.utils.T;
import com.zgscwjm.lsfbbasetemplate.view.titlebar.LsfbTitleBar;

import java.util.HashMap;


/**
 * 意见反馈
 * Created by Administrator on 2018/1/25 0025.
 */
@ContentView(R.layout.aty_feedback)
public class FeedbackActivity extends LsfbActivity {

    /**
     * 意见
     */
    @ViewInject(R.id.aty_feedback_et_import)
    private EditText et_import;

    private String session;

    @Override
    public void initView() {
        LsfbTitleBar titleBar = LittleUtils.setsimpletitlebar(this, "意见反馈");
        TextView textView = LittleUtils.rightbtn(this, "提交");

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(et_import.getWindowToken(), 0);

                postFeedback();
            }
        });
        titleBar.setRightView(textView, 0, 0, DensityUtils.dp2px(this, 10), 0);
    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    /**
     * 获取必要信息
     */
    private void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
        new BaseInternet().getData_Get(URLString.GETFBSESSION, hashMap, String.class, new GetFbsessionEvent(), true, false);
    }

    @EventAnnotation
    public void GetFbsessionEvent(GetFbsessionEvent event) {
        switch (event.getCode()) {
            case 200:
                session = event.getData();
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                finish();
                break;
        }
    }

    /**
     * 提交
     */
    public void postFeedback() {
        if (et_import.getText().toString().isEmpty()) {
            T.showShort(this, "请输入反馈内容");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("content", et_import.getText().toString());
        hashMap.put("session", session);

        new BaseInternet().getData(URLString.FEEDBACK, hashMap, FeedbackBean.class, new FeedbackEvent<FeedbackBean>(), true);
    }

    @EventAnnotation
    public void FeedbackEvent(FeedbackEvent<FeedbackBean> event) {
        switch (event.getCode()) {
            case 200:
                T.showShort(this, "提交成功");
                finish();
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                break;
        }
    }

}
